package com.example.emailWeb.Tools;

import com.example.emailWeb.ntru.polynomial.IntegerPolynomial;

public class mysqlTools {
    /**
     * 把int数组存放到mysql数据库中，存放字符串进去
     * eg: [1, 2, 3, 4, 5, 6] -> 1,2,3,4,5,6,
     * @param arr
     * @return
     */
    public static String intArrToStr(int arr[]){
        StringBuffer sb = new StringBuffer();
        for (int a:arr) {
            sb.append(a);
            sb.append(",");
        }
       return sb.toString();
    }

    public static String integerPolynomialToStr(IntegerPolynomial poly){

        StringBuffer sb = new StringBuffer();
        for (int a:poly.coeffs) {
            sb.append(a);
            sb.append(",");
        }
        return sb.toString();
    }

    /**
     * * 把int数组存放到mysql数据库中，存放字符串进去
     * eg: 1,2,3,4,5,6, -> [1, 2, 3, 4, 5, 6]
     * @param sArr
     * @return
     */
    public static int[] strToIntArr(String sArr){
        String[] splits = sArr.split(",");
        int[] intArr = new int[splits.length];
        for (int i = 0; i < splits.length; i++) {
            intArr[i] = Integer.parseInt(splits[i]);
        }
        return intArr;
    }

    public static IntegerPolynomial strToIntegerPolynomial(String sArr){
        String[] splits = sArr.split(",");
        int[] intArr = new int[splits.length];
        for (int i = 0; i < splits.length; i++) {
            intArr[i] = Integer.parseInt(splits[i]);
        }
        return new IntegerPolynomial(intArr);
    }


}
